/*******************************************************************************
 * Copyright (c) 2022 Peirlberger Juergen
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Peirlberger Juergen - initial API and implementation and/or initial documentation
 *******************************************************************************/

#ifndef SRC_MODULES_PLCNEXT_SWINTERFACE_H_
#define SRC_MODULES_PLCNEXT_SWINTERFACE_H_

// PLCnext includes
#include "Arp/System/ModuleLib/Module.h"
#include "Arp/System/Commons/Logging.h"
#include "Arp/Plc/AnsiC/Gds/DataLayout.h"
#include "Arp/Plc/AnsiC/Io/FbIoSystem.h"
#include "Arp/Plc/AnsiC/Io/Axio.h"
#include "Arp/Plc/AnsiC/Domain/PlcOperationHandler.h"
#include "Arp/System/Rsc/ServiceManager.hpp"
#include "Arp/Device/Interface/Services/IDeviceStatusService.hpp"

#include "forte/util/devlog.h"
#include <syslog.h>
#include <unistd.h>
#include <libgen.h>
#include <thread>
#include <pthread.h>
#include "forte/arch/forte_sync.h"

#include "forte/util/devlog.h"

using namespace Arp;
using namespace Arp::System::Rsc;
using namespace Arp::Device::Interface::Services;
using namespace Arp::System::Commons::Diagnostics::Logging;

class DeviceStatus;
class PLCnextDeviceInterface {

  public:
    static CSyncObject changeMutex;

    const std::string busIdentifier = "Arp.Io.AxlC";
    std::string pinName;
    int nodeId = -1;
    std::string fqPinIdentifier; // format <busIdentifier>/<nodeId>.<pinName>

    // buffer
    TGdsBuffer *gdsBuffer = NULL;

    // offset
    size_t offset = 0;

    PLCnextDeviceInterface() {};
    ~PLCnextDeviceInterface();

    const char *init(int nodeId, const char *pinName);
    void read(char *value, size_t valueSize);
    void write(char *value, size_t valueSize);
};

#endif /* SRC_MODULES_PLCNEXT_SWINTERFACE_H_ */
